/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main.models;

import java.util.ArrayList;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedProperty;
import main.game.GamesManager;
import main.game.GameConventions;

/**
 *
 * @author Ariman
 */
@ManagedBean
@ApplicationScoped
public class Hall {

    public Hall() {
        players = new ArrayList<Player>();
        createdGames = new ArrayList<CreatedGame>();
    }

    public GamesManager getGamesManager() {
        return gamesManager;
    }

    public void setGamesManager(GamesManager gamesManager) {
        this.gamesManager = gamesManager;
    }

    public ArrayList<Player> getPlayers() {
        return players;
    }

    public void setPlayers(ArrayList<Player> players) {
        this.players = players;
    }

    public ArrayList getCreatedGames() {
        return createdGames;
    }

    public void setCreatedGames(ArrayList createdGames) {
        this.createdGames = createdGames;
    }

    public String getMsg() {
        return String.valueOf(counter++);
    }

    public void removePlayer(Player player) {
        players.remove(player);
    }

    public void addPlayer(Player player) {
        if (players.contains(player)) {
            players.remove(player);
        }
        players.add(player);
    }

    public String CreateGame(Player creator, GameConventions conventions) {
        CreatedGame game = new CreatedGame();
        game.setUID(new Long(createdGames.size() + 1));
        game.setConventions(conventions);
        creator.setCreator(true);
        game.addPlayer(creator.clone());
        createdGames.add(game);
        return "succses";
    }
    
    private int counter = 0;
    
    @ManagedProperty (value = "#{gamesManager}")
    private GamesManager gamesManager;
    private ArrayList<Player> players;
    private ArrayList<CreatedGame> createdGames;
}
